package com.xt.purchasingsystem.service.impl.productDesignServiceImpl.proFileManageServiceImpl.productFileRegistrtionServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xt.purchasingsystem.dto.DFileDto;
import com.xt.purchasingsystem.mapper.DFileMapper;
import com.xt.purchasingsystem.model.DFile;
import com.xt.purchasingsystem.service.productDesignService.proFileManageService.proFileRegistrtionService.ProductFileRegistrtionService;
import com.xt.purchasingsystem.utils.Result;
import com.xt.purchasingsystem.utils.ResultFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * @author dm
 * @date 2020/3/9 11:26
 * 产品档案登记业务实现类
 */
@Service
@Transactional
public class ProductFileRegistrtionServiceImpl implements ProductFileRegistrtionService {
    @Autowired
    private DFileMapper dFileMapper;

    /**
     * 产品档案处登记添加
     *
     * @param form
     * @return
     */
    @Override
    public Result insert(DFile form) {
        int i = dFileMapper.insert(form);
        if (i == 1) {
            return ResultFactory.buildSuccessResult("添加成功");
        } else {
            return ResultFactory.buildFailResult("添加失败");
        }
    }

    @Override
    public Result checkProductName(String productName) {
        DFile dFile = dFileMapper.queryDFileByProductName(productName);
        if (dFile != null) {
            return ResultFactory.buildSuccessResult("查询成功",false);
        } else {
            return ResultFactory.buildSuccessResult("查询成功",true);
        }
    }

    @Override
    public Result getAllDFileIsMaterial(DFileDto dFileDto) {
        PageHelper.startPage(dFileDto.getCurrNo(),dFileDto.getPageSize());
        List<DFile> allDFileIsMaterial = dFileMapper.getAllDFileIsMaterial(dFileDto);
        PageInfo<DFile> pageInfo=new PageInfo<>(allDFileIsMaterial);
        return ResultFactory.buildSuccessResult("查询成功",pageInfo);
    }

    @Override
    public Result getAllNoQuotationBySupplierId(DFileDto dFileDto) {
        PageHelper.startPage(dFileDto.getCurrNo(),dFileDto.getPageSize());
        List<DFile> allDFileIsMaterial=  dFileMapper.getAllNoQuotationBySupplierId(dFileDto);
        PageInfo<DFile> pageInfo=new PageInfo<>(allDFileIsMaterial);
        return ResultFactory.buildSuccessResult("查询成功",pageInfo);
    }

}
